<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>私海管理配置</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style>
        #starDt #endDt {
            width: 120px !important;
        }
    </style>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="私海配置列表" lselected="true">
            <div class="searchArea">
                <!-- 查询表单 -->
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <div class="fieldBox">
                            <div class="label">私海名称</div>
                            <div class="field">
                                <input name="privateSeaNm" class='ui-textbox' id="privateSeaNm" type="text"/>
                            </div>
                        </div>
                        <%--<div class="fieldset1">--%>
                            <%--<div class="fieldBox">--%>
                                <%--<div class="label">管理员名称</div>--%>
                                <%--<div class="field">--%>
                                    <%--<input name="adminName" class='ui-textbox' id="adminName" type="text"/>--%>
                                <%--</div>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <div class="fieldBox">
                            <div class="label">所属事业部</div>
                            <div class="field">
                                <select name="buOrgCd" id="buOrgCd" data-value=" ">
                                    <option value=" " seleted>请选择</option>
                                    <c:forEach items="${searchBuOrgList }" var="kv">
                                        <option value="${kv.key }">${kv.value }</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="clearFix"></div>
                        <div class="btnsBox formBtns notRight">
                            <span id="searchBtn" class="sq-button-round">查询</span>
                            <span id="clearBtn" class="sq-button-round" onclick="clearBtn();">清空</span>
                            <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
                            <%--<span id="searchBtn" class="sq-button-round" onclick="searchBtnEvent()">查询</span>--%>
                            <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="sqPanel" style="margin-bottom: 0;">
                <div class="sqPanel_body">
                    <div id="ligergridDB" class="sq-grid"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    <%--=全局变量=--%>
    var gridDB = null;
    var currOrgCd = '${currOrgCd}';
    var currBuOrgCd = '${currBuOrgCd}';

    var dataId = null;
    var pageInApp = {}; // to 下一级子窗口 接口
    var pageInTab = null;
    var loadedTabs = [];

    //初始化详情数据
    //initData();
    //初始化人员信息
    //initSplRlGrid();

    $(function () {
        initTab();
        initGridDB(); //初始化列表
        $("#searchBar").ligerForm();
        $("#searchBtn").click(function (event) {
            reloadGrid();
        });
    });

    //初始化列表
    function initGridDB() {
        $("#ligergridDB").ligerGrid({
            url: '<%=path%>/spl/splprisearulecfg/initList.do',
            method: 'get',
            columns: [
                {
                    display: '私海名称',
                    width: 200,
                    enabledSort: false,
                    render: function (rowdata, rowindex, value){
                        var h='<a href="javascript:showDetail(';
                        h+="'"+rowdata.id+"'";
                        h+=')">'+rowdata.privateSeaNm+'</a>';
                        return h;
                    }
                },
                // {
                //     display: '管理员',
                //     name: 'adminNm',
                //     minWidth: 100,
                //     enabledSort: false
                // },
                {
                    display: '所属事业部',
                    name: 'buOrgCdNm',
                    minWidth: 100,
                    enabledSort: false
                },
                {
                    display: '是否支持领取',
                    minWidth: 150,
                    enabledSort: false,
                    render:function (rowdata, rowindex, value) {
                        if(rowdata.isCanReceive && rowdata.isCanReceive == 1 ){
                            return '是';
                        }
                        return '否';
                    }
                },
                {
                    display: '是否支持手动释放',
                    minWidth: 150,
                    enabledSort: false,
                    render:function (rowdata, rowindex, value) {
                        if(rowdata.isActiveRelease && rowdata.isActiveRelease == 1 ){
                            return '是';
                        }
                        return '否';
                    }
                },
                {
                    display: '是否支持自动释放',
                    minWidth: 150,
                    enabledSort: false,
                    render:function (rowdata, rowindex, value) {
                        if(rowdata.isAutoRelease && rowdata.isAutoRelease == 1 ){
                            return '是';
                        }
                        return '否';
                    }
                },
                {
                    display: '私海领取上限',
                    name: 'receiveLimitUp',
                    minWidth: 150,
                    enabledSort: false
                },
                // {
                //     display: '释放总数',
                //     name: 'releaseSeaTotal',
                //     minWidth: 100,
                //     enabledSort: false
                // },
                // {
                //     display: '公海总数',
                //     name: 'publicSeaTotal',
                //     minWidth: 100,
                //     enabledSort: false
                // },
                {
                    display: '操作', width: 450, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var j = '<a class="sq-button-hasicon" href="javascript:modifyPriSeaRule(';
                        j += "'" + rowdata.id + "'";
                        j += ')"><i class="sqBtnIco_4"></i>修改</a>';
                        return j;
                    }
                },
            ],
            pageSize: 10,
            pageSizeOptions: [10, 20, 30, 40, 50, 100], //按照自己的喜好选择不同的页面显示条数
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '40%',
            //heightDiff : -30,
            //checkbox : true,
            rownumbers: true
        });
        gridDB = liger.get("ligergridDB");
        gridDB.setHeight(100);
        gridDB.options.isSingleCheck = true;
    }

    //重新加载GRID
    function reloadGrid() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            console.log('name:' + name + ',data:' + data[name]);
            gridDB.setParm(name, data[name]);
        }
        ;
        gridDB.reload();
    }

    //格式化时间
    function renderDate(value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, "yyyy-MM-dd hh:mm");
        }
        return dateStr;
    }

    function clearBtn() {
        //$("#resetBtn").click();  //重置 input-text
        //var form = liger.get("searchBar");
        // $("#orgCd").val("");
        //form.setData({  //重置select等特殊表单
        //"orgCd": " ",
        //    "businessType":" ",
        //    "bizResCd":" "
        // });
        //searchOrgTree.clear();
        clearLigerForm("searchBar");
        //console.log($('#cstMgrOrgCdId span').text());
        //$('#cstMgrOrgCdId span').text('');
    }

    //初始化Tab页
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                currTab = tabid; //赋值是哪个Tab页面
                if (loadedTabs.indexOf(tabid) < 0) {
                    loadedTabs.push(tabid);
                    switch (tabid) {
                        case "tabB":
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/bizflow/rskUsrAchLog/toMyAchievementsPage.do");
                            break;
                    }
                }
                ;
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    }


    //修改私海规则数据
    <%--function modifyPriSeaRule(ruleId){--%>
        <%--if(!ruleId)return;--%>
        <%--Add_navTab('PrdSpl_2'+ruleId,'修改私海规则','<%=path%>/spl/splprisearulecfg/toModifyPage.do?id='+_id+'&mfrId='+_mfrId+'&splAttrCd='+_splAttrCd, callback);--%>
    <%--};--%>
    //修改数据
    function modifyPriSeaRule(ruleId){
        if(!ruleId)return;
        $.ligerDialog.SQopen({
            width: 900,
            height:550,
            title : '修改私海规则信息',
            url:'<%=path%>/spl/splprisearulecfg/toModifyPage.do?id='+ruleId,
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) Dialog.onOk();
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
    }

    //新增私海规则数据
    function add() {
        $.ligerDialog.SQopen({
            width: 900,
            height:550,
            title : '新增私海规则',
            url:'<%=path%>/spl/splprisearulecfg/toAddPage.do?currBuOrgCd='+currBuOrgCd + '&currOrgCd='+currOrgCd,
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) Dialog.onOk();
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
    }

    //详情
    function showDetail(_id){
        if(!_id)return;
        $.ligerDialog.SQopen({
            width: 900,
            height:550,
            title : '私海规则详情',
            url:'<%=path%>/spl/splprisearulecfg/toDetailPage.do?id='+_id,
            buttons: [{
                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
    }

    function iframeResize () {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        };
    }

    var callback = function () {
        gridDB.reload();
    };
    <%-- jquery==end--%>
</script>
</body>
</html>
